<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Template Attribute Language</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Template_Attribute_Language"> <link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Template_Attribute_Language rootpage-Template_Attribute_Language skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Template Attribute Language</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1251242444">
/* start https://en.wikipedia.org/ */
.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1248332772">
/* start https://en.wikipedia.org/ */
.mw-parser-output .multiple-issues-text{width:95%;margin:0.2em 0}.mw-parser-output .multiple-issues-text>.mw-collapsible-content{margin-top:0.3em}.mw-parser-output .compact-ambox .ambox{border:none;border-collapse:collapse;background-color:transparent;margin:0 0 0 1.6em!important;padding:0!important;width:auto;display:block}body.mediawiki .mw-parser-output .compact-ambox .ambox.mbox-small-left{font-size:100%;width:auto;margin:0}.mw-parser-output .compact-ambox .ambox .mbox-text{padding:0!important;margin:0!important}.mw-parser-output .compact-ambox .ambox .mbox-text-span{display:list-item;line-height:1.5em;list-style-type:disc}body.skin-minerva .mw-parser-output .multiple-issues-text>.mw-collapsible-toggle,.mw-parser-output .compact-ambox .ambox .mbox-image,.mw-parser-output .compact-ambox .ambox .mbox-imageright,.mw-parser-output .compact-ambox .ambox .mbox-empty-cell,.mw-parser-output .compact-ambox .hide-when-compact{display:none}
/* end https://en.wikipedia.org/ */
</style>
<style data-mw-deduplicate="TemplateStyles:r1236090951">
/* start https://en.wikipedia.org/ */
.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}
/* end https://en.wikipedia.org/ */
</style><div role="note" class="hatnote navigation-not-searchable">"TALES" redirects here. For other uses, see <a href="Tales_(disambiguation)" class="mw-redirect mw-disambig" title="Tales (disambiguation)">Tales</a>.</div>
<p>The <b>Template Attribute Language</b> (TAL) is a templating language used to generate dynamic <a href="HTML" title="HTML">HTML</a> and <a href="XML" title="XML">XML</a> pages. Its main goal is to simplify the collaboration between programmers and designers. This is achieved by embedding TAL statements inside valid HTML (or XML) tags which can then be worked on using common design tools.
</p><p>TAL was created for <a href="Zope" title="Zope">Zope</a> but is used in other <a href="Python_(programming_language)" title="Python (programming language)">Python</a>-based projects as well.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="TASFIA">TASFIA</h2></div>
<p>The following attributes are used, normally prefixed by "<code>tal:</code>":
</p>
<dl><dt>define</dt>
<dd>creates local variables, valid in the <a href="HTML_element" title="HTML element">element</a> bearing the attribute (including contained elements)</dd>
<dt>condition</dt>
<dd>decides whether or not to render the tag (and all contained text)</dd>
<dt>repeat</dt>
<dd>creates a loop variable and repeats the tag iterating a sequence, e.g. for creating a selection list or a table</dd>
<dt>content</dt>
<dd>replaces the content of the tag</dd>
<dt>replace</dt>
<dd>replaces the tag (and therefore is not usable together with content or attributes)</dd>
<dt>attributes</dt>
<dd>replaces the given attributes (e. g. by using <code>tal:attributes="name name; id name"</code> the name and id attributes of an input field could be set to the value of the <a href="Variable_(programming)" class="mw-redirect" title="Variable (programming)">variable</a> "<code>name</code>")</dd>
<dt>omit-tag</dt>
<dd>allows to omit the start and end tag and only render the content if the given expression is true.</dd>
<dt>on-error</dt>
<dd>if an error occurs, this attribute works like the content tag.</dd></dl>
<p>If a tag has more than one TAL attributes, they are evaluated in the above (fairly logical) order.
</p><p>In cases when no tag is present which lends itself to take the attributes, special TAL tags can be used, making the "<code>tal:</code>" prefix optional. e.g.:
</p>
<div class="mw-highlight mw-highlight-lang-xml mw-content-ltr" dir="ltr"><pre><span class="nt"><tal:if</span><span class="w"> </span><span class="na">condition=</span><span class="s">"context/itemlist"</span><span class="nt">></span>
...
<span class="nt"></tal:if></span>
</pre></div>
<p>would cause the code inside the <code>tal:if</code> tags to be used whenever the context (whatever the application server defines the context to be, e.g. an object) contains variable "<code>itemlist</code>" with a <i>true</i> value, e.g. a list containing at least one element. The identifier following the colon is arbitrary; it simply needs to be there, and to be the same for the opening and closing tag.
</p>
<div class="mw-heading mw-heading2"><h2 id="METAL">METAL</h2></div>
<p>The Macro Expansion Template Attribute Language (METAL) complements TAL, providing <a href="Macro_(computer_science)" title="Macro (computer science)">macros</a> which allow the reuse of code across template files. Both were created for <a href="Zope" title="Zope">Zope</a> but are used in other <a href="Python_(programming_language)" title="Python (programming language)">Python</a> projects as well.
</p><p>METAL complements TAL with the ability to reuse code. It allows the developer to define and use macros, which in turn may have <i>slots</i>; when using a macro, variational content can be specified for a slot.
</p><p>When generating <a href="XML" title="XML">XML</a> documents, the XML namespace must be specified
(<code>xmlns:metal="http://xml.zope.org/namespaces/metal"</code>).
</p>
<div class="mw-heading mw-heading3"><h3 id="METAL_attributes">METAL attributes</h3></div>
<p>The following attributes are recognised, normally requiring a „<code>metal:</code>“ prefix:
</p>
<dl><dt>define-macro</dt>
<dd>creates a macro</dd>
<dt>define-slot</dt>
<dd>creates a slot inside a macro</dd>
<dt>use-macro</dt>
<dd>uses a macro (normally given via a TALES path expression)</dd>
<dt>fill-slot</dt>
<dd>when using a macro, replaces the default content of the given slot</dd>
<dt>extend-macro</dt>
<dd>since <a href="Zope" title="Zope">Zope</a> v3: extends a macro, comparable to <a href="Class_(computer_science)" class="mw-redirect" title="Class (computer science)">subclassing</a>, by redefining of slots</dd></dl>
<p>Normally, just one of those is used at a time.
</p><p>In cases when no tag is present which lends itself to take the attributes, and in special cases when more than one METAL attribute is needed, special METAL tags can be used, making the „metal:“ prefix optional. E. g. (sketched with <a href="Roundup_(issue_tracker)" title="Roundup (issue tracker)">Roundup</a> in mind):
</p>
<div class="mw-highlight mw-highlight-lang-html mw-content-ltr" dir="ltr"><pre> <span class="p"><</span><span class="nt">html</span> <span class="na">metal:define-macro</span><span class="o">=</span><span class="s">"icing"</span><span class="p">></span>
...
<span class="p"><</span><span class="nt">metal:myslot</span> <span class="na">define-slot</span><span class="o">=</span><span class="s">"optional-form"</span><span class="p">></span>
...
<span class="p"></</span><span class="nt">html</span><span class="p">></span>
<span class="p"><</span><span class="nt">html</span> <span class="na">metal:use-macro</span><span class="o">=</span><span class="s">"templates/page/macros/icing"</span><span class="p">></span>
<span class="p"><</span><span class="nt">form</span> <span class="na">metal:fill-slot</span><span class="o">=</span><span class="s">"optional-form"</span> <span class="na">action</span><span class="o">=</span><span class="s">"."</span>
<span class="na">tal:attributes</span><span class="o">=</span><span class="s">"action context/designator"</span><span class="p">></span>
...
<span class="p"></</span><span class="nt">form</span><span class="p">></span>
<span class="p"></</span><span class="nt">html</span><span class="p">></span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="Usage">Usage</h2></div>
<p>TAL/TALES/METAL are used by the following projects:
</p>
<ul><li><a href="Zope" title="Zope">Zope</a> (web application server)</li>
<li><a href="Roundup_(issue_tracker)" title="Roundup (issue tracker)">Roundup (issue tracker)</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="Other_implementations">Other implementations</h2></div>
<p>Besides the original <a href="Zope" title="Zope">Zope</a> implementation, there are (not exhaustive):
</p>
<div class="mw-heading mw-heading3"><h3 id="Python">Python</h3></div>
<ul><li>SimpleTAL</li>
<li>OpenTAL</li>
<li>ZPT, a standalone version of <a href="Zope_Page_Templates" class="mw-redirect" title="Zope Page Templates">Zope Page Templates</a></li>
<li>Chameleon, a fast reimplementation of <a href="Zope_Page_Templates" class="mw-redirect" title="Zope Page Templates">Zope Page Templates</a></li></ul>
<div class="mw-heading mw-heading3"><h3 id="C#">C#</h3></div>
<ul><li>SharpTAL</li></ul>
<div class="mw-heading mw-heading3"><h3 id="Go_(Golang)">Go (Golang)</h3></div>
<ul><li>tal, a native Go implementation of TAL, TALES and METAL</li></ul>
<div class="mw-heading mw-heading3"><h3 id="JavaScript">JavaScript</h3></div>
<ul><li><a rel="nofollow" class="external text" href="https://github.com/jhiver/template-tal">template-tal</a>, TAL Implementation for <a href="NodeJs" class="mw-redirect" title="NodeJs">NodeJs</a></li>
<li>jstal</li>
<li>Distal</li>
<li>DomTal</li>
<li>ZPT-JS</li></ul>
<div class="mw-heading mw-heading3"><h3 id="Java">Java</h3></div>
<ul><li>JPT: <a href="Java_(programming_language)" title="Java (programming language)">Java</a> Page Templates</li>
<li>JavaZPT</li>
<li>ZPT-Java</li></ul>
<div class="mw-heading mw-heading3"><h3 id="Perl">Perl</h3></div>
<ul><li>PETAL, the <a href="Perl" title="Perl">Perl</a> Template Attribute Language</li>
<li>Template-TAL</li></ul>
<div class="mw-heading mw-heading3"><h3 id="Raku">Raku</h3></div>
<ul><li>Flower, a <a href="Raku_(programming_language)" title="Raku (programming language)">Raku</a> implementation of TAL, with some Petal and PHPTAL extensions.</li></ul>
<div class="mw-heading mw-heading3"><h3 id="PHP">PHP</h3></div>
<ul><li>PHPTAL</li>
<li>Twital</li>
<li>Biscuit</li>
<li>zTAL</li></ul>
<div class="mw-heading mw-heading3"><h3 id="XSL">XSL</h3></div>
<ul><li>XSLTal, transforming TAL via <a href="XSLT" title="XSLT">XSLT</a> to <a href="XSLT" title="XSLT">XSLT</a></li></ul>
<div class="mw-heading mw-heading3"><h3 id="Common_Lisp">Common Lisp</h3></div>
<ul><li>TALCL: A library that implements the TAL template language for <a href="Common_Lisp" title="Common Lisp">common lisp</a></li></ul>
<div class="mw-heading mw-heading3"><h3 id="Similar_implementations">Similar implementations</h3></div>
<ul><li>ATal – Not really a TAL implementation, but inspired on TAL concepts</li>
<li><a href="Thymeleaf" title="Thymeleaf">Thymeleaf</a> - Not a TAL implementation, but a similar "natural template" language</li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */
.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}
/* end https://en.wikipedia.org/ */
</style><div class="reflist">
</div>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<ul><li><a rel="nofollow" class="external text" href="https://zope.readthedocs.io/en/latest/zopebook/AppendixC.html">Zope Page Templates Reference</a> (Zope Book)</li></ul></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-07-21" href="https://en.wikipedia.org/wiki/?title=Template_Attribute_Language&oldid=1301715331">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
</body></html>